home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-30 | 12.7 KB | 556 lines | [TEXT/CWIE] |
- { Buttons.p }
- { Created 10/30/98 1:06 PM by AppMaker }
-
- Unit Buttons;
- Interface
-
- Uses
- Types,
- Quickdraw,
- Controls,
- Dialogs,
- Events,
- Lists,
- Menus,
- Resources,
- TextEdit,
- ToolUtils,
-
- DDocData,
- EverythingEngine,
- EverythingDoc,
- AMWindow;
-
- type
- Buttons = object (AMWindow)
-
- {data members}
- mData: DDocData;
- mCapInvisibleLabel: ControlHandle;
- mInvisibleHandle: ControlHandle;
- mStandardHandle: ControlHandle;
- mDefaultHandle: ControlHandle;
- mBevelHandle: ControlHandle;
- mButtonHandle: ControlHandle;
- mNextHandle: ControlHandle;
- mNext2Handle: ControlHandle;
- mGraphicHandle: ControlHandle;
- mCapcicnLabel: ControlHandle;
- mRightHandle: ControlHandle;
- mCapicl8Label: ControlHandle;
- mLightHandle: ControlHandle;
- mCapICNLabel: ControlHandle;
- mRight2Handle: ControlHandle;
- mCapicl9Label: ControlHandle;
- mButton2Handle: ControlHandle;
- mRight3Handle: ControlHandle;
- mCapPICTLabel: ControlHandle;
- mRect3DHandle: ControlHandle;
- mLeftIconHandle: ControlHandle;
- mRightIconHandle: ControlHandle;
- mTitledPICTHandle: ControlHandle;
-
- {methods}
- Procedure Initialize; Override;
-
- Procedure Open (inDoc: EverythingDoc;
- inData: DDocData);
- Procedure Close; Override;
-
- Procedure Control (whichControl: ControlHandle;
- whichPart: integer;
- where: Point); Override;
- Procedure MouseIn (where: Point;
- modifiers: integer); Override;
- Procedure TypeIn (charCode: SInt16); Override;
- Procedure ExitCurField; Override;
- Procedure DataChanged (inDataID: longint); Override;
- Procedure Resize; Override;
- Procedure Scroll (newValue: integer;
- oldValue: integer); Override;
-
- Function GetEngine: EverythingEngine;
-
- {$ifc false}
- Procedure UpdateMenus; Override;
- {$endif}
- Function DoCommand (inCommand: longint): Boolean; Override;
-
- Procedure DoUndo;
- Procedure DoCut;
- Procedure DoCopy;
- Procedure DoPaste;
- Procedure DoClear;
- Procedure DoSelectAll;
- Procedure DoShowClipboard;
-
- end;
-
- {----------}
- Procedure CreateButtons (inDoc: EverythingDoc;
- inData: DDocData);
-
- {----------}
- Implementation
-
- Uses
- Globals,
- ResourceDefs,
- DoScrap,
- Scrolling,
- ControlUtils,
- Miscellany;
-
- const
- kCapInvisibleLabel = 1;
- kInvisibleButton = 2;
- kStandardButton = 3;
- kDefaultButton = 4;
- kBevelBox = 5;
- kButtonButton = 6;
- kNextButton = 7;
- kNext2Button = 8;
- kGraphicBox = 9;
- kCapcicnLabel = 10;
- kRightButton = 11;
- kCapicl8Label = 12;
- kLightButton = 13;
- kCapICNLabel = 14;
- kRight2Button = 15;
- kCapicl9Label = 16;
- kButton2Button = 17;
- kRight3Button = 18;
- kCapPICTLabel = 19;
- kRect3DButton = 20;
- kLeftIconButton = 21;
- kRightIconButton = 22;
- kTitledPICTButton = 23;
-
- {----------}
- Procedure CreateButtons (
- inDoc: EverythingDoc;
- inData: DDocData);
- var
- winObj: Buttons;
- begin
- winObj := nil;
- New (winObj);
-
- if winObj <> nil then begin
- winObj.Initialize;
- winObj.Open (inDoc, inData);
- end;
- end;
-
- {----------}
- Procedure Buttons.Initialize;
- begin
- Inherited Initialize;
- end;
-
- {----------}
- Function Buttons.GetEngine: EverythingEngine;
- begin
- GetEngine := EverythingEngine (mDoc.mEngine);
- end;
-
- {----------}
- Procedure Buttons.Open (
- inDoc: EverythingDoc;
- inData: DDocData);
- var
- window: WindowPtr;
- wftb: Handle;
- errCode: OSErr;
- begin
- mDoc := inDoc;
- mData := inData;
- mData.AddResponder (self);
-
- window := GetNewCWindow (WIND_Buttons, nil, WindowPtr (-1));
- if inDoc.mEngine.GetFilename <> '' then begin
- SetWTitle (window, inDoc.mEngine.GetFilename);
- end;
- mWindow := window;
- EverythingDoc (mDoc).mButtonsPtr := window;
-
- WindowPeek (window)^.windowKind := kAMWindowFlag;
- SetWRefCon (window, ord4 (self));
- SetPort (window);
- SetInfo (window);
-
- wftb := GetResource ('Wftb', WIND_Buttons);
-
- errCode := CreateRootControl (window, mRootControl);
-
- vScroll := nil;
- hScroll := nil;
-
-
- mCapInvisibleLabel := GetNewControl (CNTL_CapInvisible, window);
- SetWindowItemFont (mCapInvisibleLabel, wftb, 1);
- SetControlFromTEXT (mCapInvisibleLabel, TEXT_CapInvisible);
-
- mInvisibleHandle := GetNewControl (CNTL_Invisible, window);
- SetWindowItemFont (mInvisibleHandle, wftb, 2);
-
- mStandardHandle := GetNewControl (CNTL_Standard, window);
- SetWindowItemFont (mStandardHandle, wftb, 3);
-
- mDefaultHandle := GetNewControl (CNTL_Default, window);
- SetWindowItemFont (mDefaultHandle, wftb, 4);
- SetDefaultState (mDefaultHandle, true);
-
- mBevelHandle := GetNewControl (CNTL_Bevel, window);
- SetWindowItemFont (mBevelHandle, wftb, 5);
-
- mButtonHandle := GetNewControl (CNTL_Button, window);
- errCode := EmbedControl (mButtonHandle, mBevelHandle);
- SetWindowItemFont (mButtonHandle, wftb, 6);
- errCode := SetBevelButtonGraphicAlignment (mButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
-
- mNextHandle := GetNewControl (CNTL_Next, window);
- errCode := EmbedControl (mNextHandle, mBevelHandle);
- SetWindowItemFont (mNextHandle, wftb, 7);
- errCode := SetBevelButtonTextPlacement (mNextHandle, kControlBevelButtonPlaceToRightOfGraphic);
- errCode := SetBevelButtonTextAlignment (mNextHandle, kControlBevelButtonAlignTextFlushLeft, 0);
- errCode := SetBevelButtonGraphicAlignment (mNextHandle, kControlBevelButtonAlignLeft, 0, 0);
-
- mNext2Handle := GetNewControl (CNTL_Next2, window);
- errCode := EmbedControl (mNext2Handle, mBevelHandle);
- SetWindowItemFont (mNext2Handle, wftb, 8);
- errCode := SetBevelButtonTextPlacement (mNext2Handle, kControlBevelButtonPlaceBelowGraphic);
- errCode := SetBevelButtonTextAlignment (mNext2Handle, kControlBevelButtonAlignTextCenter, 0);
- errCode := SetBevelButtonGraphicAlignment (mNext2Handle, kControlBevelButtonAlignTop, 0, 0);
-
- mGraphicHandle := GetNewControl (CNTL_Graphic, window);
- SetWindowItemFont (mGraphicHandle, wftb, 9);
-
- mCapcicnLabel := GetNewControl (CNTL_Capcicn, window);
- errCode := EmbedControl (mCapcicnLabel, mGraphicHandle);
- SetWindowItemFont (mCapcicnLabel, wftb, 10);
- SetControlFromTEXT (mCapcicnLabel, TEXT_Capcicn);
-
- mRightHandle := GetNewControl (CNTL_Right, window);
- errCode := EmbedControl (mRightHandle, mGraphicHandle);
- SetWindowItemFont (mRightHandle, wftb, 11);
-
- mCapicl8Label := GetNewControl (CNTL_Capicl8, window);
- errCode := EmbedControl (mCapicl8Label, mGraphicHandle);
- SetWindowItemFont (mCapicl8Label, wftb, 12);
- SetControlFromTEXT (mCapicl8Label, TEXT_Capicl8);
-
- mLightHandle := GetNewControl (CNTL_Light, window);
- errCode := EmbedControl (mLightHandle, mGraphicHandle);
- SetWindowItemFont (mLightHandle, wftb, 13);
-
- mCapICNLabel := GetNewControl (CNTL_CapICN, window);
- errCode := EmbedControl (mCapICNLabel, mGraphicHandle);
- SetWindowItemFont (mCapICNLabel, wftb, 14);
- SetControlFromTEXT (mCapICNLabel, TEXT_CapICN);
-
- mRight2Handle := GetNewControl (CNTL_Right2, window);
- errCode := EmbedControl (mRight2Handle, mGraphicHandle);
- SetWindowItemFont (mRight2Handle, wftb, 15);
-
- mCapicl9Label := GetNewControl (CNTL_Capicl9, window);
- errCode := EmbedControl (mCapicl9Label, mGraphicHandle);
- SetWindowItemFont (mCapicl9Label, wftb, 16);
- SetControlFromTEXT (mCapicl9Label, TEXT_Capicl9);
-
- mButton2Handle := GetNewControl (CNTL_Button2, window);
- errCode := EmbedControl (mButton2Handle, mGraphicHandle);
- SetWindowItemFont (mButton2Handle, wftb, 17);
-
- mRight3Handle := GetNewControl (CNTL_Right3, window);
- errCode := EmbedControl (mRight3Handle, mGraphicHandle);
- SetWindowItemFont (mRight3Handle, wftb, 18);
-
- mCapPICTLabel := GetNewControl (CNTL_CapPICT, window);
- errCode := EmbedControl (mCapPICTLabel, mGraphicHandle);
- SetWindowItemFont (mCapPICTLabel, wftb, 19);
- SetControlFromTEXT (mCapPICTLabel, TEXT_CapPICT);
-
- mRect3DHandle := GetNewControl (CNTL_Rect3D, window);
- SetWindowItemFont (mRect3DHandle, wftb, 20);
-
- mLeftIconHandle := GetNewControl (CNTL_LeftIcon, window);
- SetWindowItemFont (mLeftIconHandle, wftb, 21);
-
- mRightIconHandle := GetNewControl (CNTL_RightIcon, window);
- SetWindowItemFont (mRightIconHandle, wftb, 22);
-
- mTitledPICTHandle := GetNewControl (CNTL_TitledPICT, window);
- SetWindowItemFont (mTitledPICTHandle, wftb, 23);
-
- errCode := AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- end;
-
- {----------}
- Procedure Buttons.Close;
- begin
- mData.RemoveResponder (self);
-
- EverythingDoc (mDoc).mButtonsPtr := nil;
- SetInfo (nil);
- HideWindow (mWindow);
- DisposeWindow (mWindow);
-
- Dispose (self);
- end;
-
- {----------}
- Procedure Buttons.Control (
- whichControl: ControlHandle;
- whichPart: integer;
- where: Point);
- var
- bounds: Rect;
- newValue: integer;
- partcode: SInt16;
- begin
- ExitCurField ();
-
- if whichControl = mInvisibleHandle then begin
- if TrackClick (mInvisibleHandle, where) then begin
- end;
- end;
- if whichControl = mStandardHandle then begin
- if TrackClick (mStandardHandle, where) then begin
- end;
- end;
- if whichControl = mDefaultHandle then begin
- if TrackClick (mDefaultHandle, where) then begin
- end;
- end;
- if whichControl = mButtonHandle then begin
- if TrackClick (mButtonHandle, where) then begin
- end;
- end;
- if whichControl = mNextHandle then begin
- if TrackClick (mNextHandle, where) then begin
- end;
- end;
- if whichControl = mNext2Handle then begin
- if TrackClick (mNext2Handle, where) then begin
- end;
- end;
- if whichControl = mRightHandle then begin
- if TrackClick (mRightHandle, where) then begin
- end;
- end;
- if whichControl = mLightHandle then begin
- if TrackClick (mLightHandle, where) then begin
- end;
- end;
- if whichControl = mRight2Handle then begin
- if TrackClick (mRight2Handle, where) then begin
- end;
- end;
- if whichControl = mButton2Handle then begin
- if TrackClick (mButton2Handle, where) then begin
- end;
- end;
- if whichControl = mRight3Handle then begin
- if TrackClick (mRight3Handle, where) then begin
- end;
- end;
- if whichControl = mRect3DHandle then begin
- if TrackClick (mRect3DHandle, where) then begin
- end;
- end;
- if whichControl = mLeftIconHandle then begin
- if TrackClick (mLeftIconHandle, where) then begin
- end;
- end;
- if whichControl = mRightIconHandle then begin
- if TrackClick (mRightIconHandle, where) then begin
- end;
- end;
- if whichControl = mTitledPICTHandle then begin
- if TrackClick (mTitledPICTHandle, where) then begin
- end;
- end;
- end;
-
- {----------}
- Procedure Buttons.DataChanged (
- inDataID: longint);
- begin
- End;
-
- {----------}
- Procedure Buttons.MouseIn (
- where: Point;
- modifiers: integer);
- var
- bounds: Rect;
- begin
- end;
-
- {----------}
- Procedure Buttons.ExitCurField;
- var
- errCode: OSErr;
- focus: ControlHandle;
- begin
- errCode := GetKeyboardFocus (mWindow, focus);
-
- if focus = nil then begin
- { nothing to exit }
-
- end;
- inherited ExitCurField;
- end;
-
- {----------}
- Procedure Buttons.TypeIn (
- charCode: SInt16);
- var
- ch: char;
- errCode: OSErr;
- focus: ControlHandle;
- keyCode: SInt16;
- partcode: SInt16;
- begin
- errCode := GetKeyboardFocus (mWindow, focus);
-
- ch := chr (charCode);
- if (ch = charEnter)
- | (ch = charReturn) then begin
- ExitCurField;
- SimulateClick (mDefaultHandle);
- end else if ch = charEsc then begin
- end else if ch = charTab then begin
- DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
- end else if focus <> nil then begin
- keyCode := BAnd (curEvent.message, keyCodeMask);
- partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
- mDoc.mEngine.SetDirty;
- end else begin
- SysBeep (1);
- end;
- end;
-
- {----------}
- Procedure Buttons.Resize;
- begin
- { application-specific code to resize items in window }
- end;
-
- {----------}
- Procedure Buttons.Scroll (
- newValue: integer;
- oldValue: integer);
- begin
- { application-specific code to scroll window }
- if gWhichScroll = vScroll then begin
- end else begin { horizontal }
- end;
- end;
-
- {----------}
- Procedure Buttons.DoUndo;
- begin
- end; {DoUndo}
-
- {----------}
- Procedure Buttons.DoCut;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TECut (curTE);
- mDoc.mEngine.SetDirty;
- scrapDirty := true;
- end;
- end; {DoCut}
-
- {----------}
- Procedure Buttons.DoCopy;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TECopy (curTE);
- scrapDirty := true;
- end;
- end; {DoCopy}
-
- {----------}
- Procedure Buttons.DoPaste;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TEPaste (curTE);
- mDoc.mEngine.SetDirty;
- end;
- end; {DoPaste}
-
- {----------}
- Procedure Buttons.DoClear;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TEDelete (curTE);
- mDoc.mEngine.SetDirty;
- end;
- end; {DoClear}
-
- {----------}
- Procedure Buttons.DoSelectAll;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TESetSelect (0, 32767, curTE);
- end;
- end; {DoSelectAll}
-
- {----------}
- Procedure Buttons.DoShowClipboard;
- begin
- end; {DoShowClipboard}
-
- {----------}
- Function Buttons.DoCommand (
- inCommand: longint): Boolean;
- begin
- DoCommand := true;
- case inCommand of
- cmdUndo:
- DoUndo;
- cmdCut:
- DoCut;
- cmdCopy:
- DoCopy;
- cmdPaste:
- DoPaste;
- cmdClear:
- DoClear;
- cmdSelectAll:
- DoSelectAll;
- cmdShowClipboard:
- DoShowClipboard;
-
- otherwise
- DoCommand := false;
- end; {case}
- end;
-
- end.
-